import VitePluginOss from 'vite-plugin-oss';
import topLevelAwait from 'vite-plugin-top-level-await';
import { defineApplicationConfig } from '@vben/vite-config';

export default defineApplicationConfig({
  overrides: {
    plugins: [
      topLevelAwait(),
      VitePluginOss({
        from: './dist/**', // 上传那个文件或文件夹
        dist: '/', // 需要上传到oss上的给定文件目录
        region: 'oss-cn-guangzhou',
        accessKeyId: 'LTAI5tQP9gdQnFioFWscL42V',
        accessKeySecret: 'glwjlXQFxNJH8CPN0w98wVFOneimWf',
        bucket: `printing-helper-banckend-web`,
        test: false, // 测试，可以在进行测试看上传路径是否正确, 打开后只会显示上传路径并不会真正上传。默认false
        // 因为文件标识符 "\"  和 "/" 的区别 不进行 setOssPath配置,上传的文件夹就会拼到文件名上, 丢失了文件目录,所以需要对setOssPath 配置。
        setOssPath: (filePath) => {
          const index = filePath.lastIndexOf('dist');
          const Path = filePath.substring(index + 4, filePath.length);
          return Path.replace(/\\/g, '/');
        },
      }),
    ] as any,
    optimizeDeps: {
      include: [
        'echarts/core',
        'echarts/charts',
        'echarts/components',
        'echarts/renderers',
        'qrcode',
        '@iconify/iconify',
        'ant-design-vue/es/locale/zh_CN',
        'ant-design-vue/es/locale/en_US',
      ],
      exclude: ['mc-c2b2m-operator-api'],
    },
    server: {
      proxy: {
        '/basic-api': {
          target: 'http://localhost:3000',
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(new RegExp(`^/basic-api`), ''),
          // only https
          // secure: false
        },
        '/upload': {
          target: 'http://localhost:3300/upload',
          changeOrigin: true,
          ws: true,
          rewrite: (path) => path.replace(new RegExp(`^/upload`), ''),
        },
      },
      open: true, // 项目启动后，自动打开
      warmup: {
        clientFiles: ['./index.html', './src/{views,components}/*'],
      },
    },
  },
});
